package com.woniuxy.lab.woniu_lab_boss.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.lab.woniu_lab_boss.model.Log;
import com.woniuxy.lab.woniu_lab_boss.dao.LogDao;
import com.woniuxy.lab.woniu_lab_boss.model.User;
import com.woniuxy.lab.woniu_lab_boss.service.LogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.lab.woniu_lab_boss.service.dto.LogDto;
import com.woniuxy.lab.woniu_lab_boss.service.dto.UserDto;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 靶场日志表 服务实现类
 * </p>
 *
 * @author Silas
 * @since 2023-03-15
 */
@Service
public class LogServiceImpl extends ServiceImpl<LogDao, Log> implements LogService {
    @Resource
    private LogDao logDao;

    @Override
    public IPage<LogDto> findAll(Integer page, Integer size) {
        IPage<Log> iPage = new Page<>(page == null ? 1 : page, size == null ? 4 : size);
        IPage<Log> page1 = logDao.selectPage(iPage, new QueryWrapper<Log>().orderByDesc("log_time"));
        return page1.convert(u -> {
            LogDto logDto = new LogDto();
            BeanUtils.copyProperties(u, logDto);
            return logDto;
        });
    }
}
